package goutils

import (
	"crypto/md5"
	"encoding/hex"
	"os"
	"os/signal"
	"time"
)

func MD5(str string) string {
	h := md5.New()
	h.Write([]byte(str))
	return hex.EncodeToString(h.Sum(nil))
}

// 检查是否是root用户运行
func CheckRoot() bool {
	uid := os.Geteuid()
	return uid == 0
}

func WaitExit() {
	quitSignal := make(chan os.Signal)
	signal.Notify(quitSignal, os.Interrupt, os.Kill)
	<-quitSignal
}

func Sleep(ms int) {
	time.Sleep(time.Duration(ms) * time.Millisecond)
}

func Timestamp() int64 {
	return time.Now().Unix()
}
